package com.acpt.util;

import com.acpt.vo.ErrorVO;
import com.alibaba.fastjson.JSONObject;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;

public class ResponseUtils {
  private static final String CONTENT_TYPE = "application/json;charset=utf-8";

  public static void buildResponse(HttpServletResponse response, String msg, String httpStatus) throws IOException {
    response.setContentType(CONTENT_TYPE); // 返回JSON
    response.setStatus(HttpStatus.OK.value());  // 状态码
    ErrorVO errorVO = new ErrorVO(httpStatus, msg);
    response.getWriter().write(JSONObject.toJSONString(errorVO));
  }


}
